/**
 * Created by gengrong on 16/5/7.
 */
import { SmartForm } from 'comps/common';
import { Form, Row, Col, Button, Input } from 'antd';
import * as React from 'react';

class RunnableGroupConfigForm extends React.Component {

  doSubmit(evt) {
    evt.preventDefault();
    this.props.smartSubmit(values => {
      if (values.id === undefined) {
        return this.props.onSubmit(values);
      }
    });
  }

  render() {
    const { form, detail, submiting } = this.props;

    const nameProps = form.getFieldProps('name', {
      initialValue: detail.runnableGroup.name
    });
    const descProps = form.getFieldProps('desc', {
      initialValue: detail.runnableGroup.desc
    });

    return (
      <Form horizontal onSubmit={::this.doSubmit}>
        <Form.Item labelCol={{ span: 6 }} wrapperCol={{ span: 14 }} label='项目名称：'>
          <Input {...nameProps}/>
        </Form.Item>
        <Form.Item labelCol={{ span: 6 }} wrapperCol={{ span: 14 }} label='项目描述：'>
          <Input className='runnable-group-desc' rows='6' type='textarea' {...descProps}/>
        </Form.Item>
        <Row type='flex' justify='center'>
          <Col span='12'>
            <Button htmlType='submit' type='primary' loading={submiting}>提交</Button>
          </Col>
        </Row>
      </Form>
    );
  }
}

RunnableGroupConfigForm = Form.create({})(SmartForm.beSmart()(RunnableGroupConfigForm));

export default RunnableGroupConfigForm;
